app.controller('UpKeepingEndCtrl', function($scope, $ionicConfig,radialIndicatorInstance, $state, $stateParams, $timeout, $ionicHistory, PopupService,$http,$myconfig) {
    $scope.type = $stateParams.type;
    $scope.indicatorOption = {
        radius : 41,
        percentage :true,
        barColor : "#009cff",
        barBgColor: "#FFFFFF",
        roundCorner: true,
        barWidth: 4,
        displayNumber: false,
        // frameTime: 1500,
        initValue : 0
    };
    $scope.indicatorOption1 = {
        radius : 41,
        percentage :true,
        barColor : "#18c756",
        barBgColor: "#FFFFFF",
        roundCorner: true,
        barWidth: 4,
        displayNumber: false,
        // frameTime: 1500,
        initValue : 0
    };

    $timeout(function () {
        radialIndicatorInstance['indicator_time1'].animate(100);
        radialIndicatorInstance['indicator_power1'].animate(100);

    }, 1000);



	function hh(val) {
		var c2 = document.getElementById("myCanvas3");
		var ctx2 = c2.getContext("2d");
		ctx2.shadowBlur = 80;
		ctx2.shadowColor = "red";
		ctx2.fillStyle = "blue";
		ctx2.beginPath();
		ctx2.lineWidth = 1;
		ctx2.fillStyle = "rgba(0,0,0,0)";
		ctx2.shadowBlur = 20;
		ctx2.shadowColor = "rgba(0,0,0,0)";
		ctx2.strokeStyle = "#009CFF";
		ctx2.lineCap = "round";
		ctx2.arc(50, 50, 40, 1.5 * Math.PI, (1.5 + val) * Math.PI); //最大设置为（3.4 * Math.PI） 为一圈；
		ctx2.fill();
		ctx2.stroke();
		ctx2.save();
	}

	//把时间换算成毫秒秒。10毫秒执行一次。每次i增加10,当i大于治疗时间停止治疗。
	var zong1 = 40; //治疗的时间秒数
	var chuliang = 20; //换算成毫秒
	var data1 = 0;
	var jia1 = chuliang / 50;
	var r = (data1 / zong) * 2;
	$scope.data1 = 0;
	var i=0;
	function Timing_rotation() {
		r = (data1 / zong1) * 2;
		hh(r);
		i++;
		// console.log(i);
		data1 = data1 + jia1;
		$scope.data1 = parseInt(data1);
		$scope.$apply(); //刷新视图
		if (data1 > chuliang) {
			$scope.data1 = chuliang;
			clearInterval(tim);
			$scope.$apply(); //刷新视图
		}
	}

	// var tim = setInterval(Timing_rotation, 10);

	function hh2(val) {
		var c2 = document.getElementById("myCanvas4");
		var ctx2 = c2.getContext("2d");
		ctx2.shadowBlur = 80;
		ctx2.shadowColor = "red";
		ctx2.fillStyle = "blue";
		ctx2.beginPath();
		ctx2.lineWidth = 1;
		ctx2.fillStyle = "rgba(0,0,0,0)";
		ctx2.shadowBlur = 20;
		ctx2.shadowColor = "rgba(0,0,0,0)";
		ctx2.strokeStyle = "#18C756";
		ctx2.lineCap = "round";
		ctx2.arc(50, 50, 40, 1.5 * Math.PI, (1.5 + val) * Math.PI); //最大设置为（3.4 * Math.PI） 为一圈；
		ctx2.fill();
		ctx2.stroke();
		ctx2.save();
	}


	var wanchegn = 300,
		zong = 900,
		date2 = 0;
	var jiajia = 300 / 50;
	// console.log(jiajia);
	$scope.ts2 = 0;
	var r2 = (date2 / zong) * 2;
	var y=0;
	//把时间换算成毫秒秒。10毫秒执行一次。每次i增加10,当i大于治疗时间停止治疗。
	function Timing_rotation2() {
		date2 = date2 + jiajia;
		$scope.ts2 = date2;
		y++;
		// console.log(y);
		r2 = (date2 / zong) * 2;
		hh2(r2);
		$scope.$apply(); //刷新视图
		if (date2 > wanchegn) {
			$scope.ts2 = wanchegn;
			clearInterval(tim2);
			$scope.$apply(); //刷新视图
		}
	}
	// var tim2 = setInterval(Timing_rotation2, 10);


	$scope.open_share = function () {
        PopupService.popShare($scope);
    };

	$scope.go_back = function () {
        $ionicHistory.nextViewOptions({
            disableAnimate: true,
            disableBack: true,
            historyRoot: true
        });
        $state.go('app.YanZhiBao');
    };
    $scope.$on('$ionicView.enter', function(){

        $ionicConfig.views.swipeBackEnabled(false);

    });
});
